package com.bw.controller;

import com.bw.bean.Cloumn;
import com.bw.bean.User;
import com.bw.service.CloumnService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class CloumnController {
@Resource
    private CloumnService cloumnService;
    @RequestMapping("list")
    public String list(Cloumn cloumn, Model model){
        List<Cloumn> list = cloumnService.list(cloumn);
        model.addAttribute("list",list);
        model.addAttribute("cloumn",cloumn);
        return "list";
    }

    @RequestMapping("tologin")
    public String tologin(){
        return "login";
    }
    @RequestMapping("login")
    @ResponseBody
    public Boolean login(User user, HttpSession session){
        List<User> login = cloumnService.login(user);
        if(login.size()>0){
            session.setAttribute("user",1);
            return true;
        }else{
            return false;
        }
    }

    @RequestMapping("toadd")
    public String toadd(){
        return "add";
    }

    @RequestMapping("add")
    @ResponseBody
    public Boolean add(Cloumn cloumn){
        cloumnService.insert(cloumn);
        return true;
    }
}
